package com.onetoall.yjt;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;

import java.util.ArrayList;

/**
 * Created by DELL on 2016/12/30.
 */

public class TestActivity extends Activity {
    RecyclerView recyclerView;
    private ArrayList arrayList;
    private AnimationAdapter adapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_animation);
        recyclerView = (RecyclerView) findViewById(R.id.anim_rl);
        arrayList = new ArrayList();
        for (int i = 0; i < 50; i++) {
            arrayList.add(">>>>>>>"+i);
        }
        LinearLayoutManager manager = new LinearLayoutManager(getBaseContext());
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(manager);
        adapter = new AnimationAdapter(arrayList,getBaseContext());
        recyclerView.setAdapter(adapter);
       final Animation taLeft = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 1.0f,
                Animation.RELATIVE_TO_PARENT, 0.0f,
                Animation.RELATIVE_TO_PARENT, 0.0f,
                Animation.RELATIVE_TO_PARENT, 0.0f);
        taLeft.setDuration(1000);

        new Thread(){
            @Override
            public void run() {
                super.run();
                try {
                    Thread.sleep(2000);
                    System.out.println(">>>");
                    handler.sendEmptyMessage(0);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }.start();

    }
    Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            System.out.println(">>>");
//            adapter.addData(0);

            arrayList.add(0,"新增");

            adapter.notifyDataSetChanged();

//            adapter.addData(0);
//            recyclerView.scrollToPosition(0);
        }
    };
}
